<?php

namespace App\Jobs\TrainQuery;

use App\Trip\Train\Providers\Ctrip\Transfer;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class ProcessRefreshTransfersQuery implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public int    $retry = 1;
    private array $param;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(array $param)
    {
        $this->param = $param;
    }

    /**
     * Execute the job.
     *
     * @return void
     * @throws GuzzleException
     */
    public function handle()
    {
        $transfer = new Transfer();
        $transfer->transfer($this->param, true);
    }

    public function uniqueId(): string
    {
        return "RefreshTransferQuery:{$this->param['from_code']}:{$this->param['to_code']}:{$this->param['train_date']}";
    }
}
